package com.bfxy.rabbitmq.message;

import com.bfxy.rabbitmq.util.RabbitUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by deng_wb on 2020/3/9
 */
@SuppressWarnings("all")
public class Procuder {

    public static void main(String[] args) throws Exception {

        // 3. 通过connection创建一个Channel
        Channel channel = RabbitUtil.producerChannel();

        Map<String, Object> headers = new HashMap<>();
        headers.put("my1", "111");
        headers.put("my2", "222");

        AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder()
                .deliveryMode(2) // 持久化配置
                .contentEncoding("UTF-8")
                .expiration("10000") // 设置过期时间
                .headers(headers)   // 设置自定义属性
                .build();

        // 4. 通过Channel发送数据
        String msg = "Hello RabbitMQ!";

        channel.basicPublish("", "test001", properties, msg.getBytes());


        // 5. 记得要关闭相关连接
        channel.close();
    }
}
